package com.yyq.adms.sysmanage.bpo.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yyq.adms.sysmanage.bpo.DataDictionaryBpo;
import com.yyq.adms.sysmanage.dao.DataDictionaryDao;
import com.yyq.adms.sysmanage.pojo.DataDictionary;
import com.yyq.adms.usermanage.pojo.SysDepts;
import com.yyq.sos.permission.LoginUser;
import com.yyq.sos.service.BaseBpoImpl;

@Service("dataDictionaryBpo")
@Transactional
public class DataDictionaryBpoImpl extends BaseBpoImpl implements
		DataDictionaryBpo {

	private DataDictionaryDao dao;
	@Resource(name="dataDictionaryDao") 
	public void setDao(DataDictionaryDao dao) {
		this.dao = dao;
		super.setBaseDao(dao);
	}
	public List getDepts(LoginUser user) {
		List data = new ArrayList();
		recursionGetDept(user.getOrgId(),data);
		return data;
	}

	private void recursionGetDept(Long deptId,List data){
		String hql = "from SysDepts where sts='ACTV' and deptType=0 and parentId="+deptId;
		List list = dao.search(hql);
		if(list != null && list.size()>0){
			data.addAll(list);
			for(int i=0;i<list.size();i++){
				SysDepts d = (SysDepts)list.get(i);
				recursionGetDept(d.getId(),data);
			}
		}
	}
	public List getCompany() {
		String hql = "from SysDepts where deptType=1 and parentId=0";
		List d = dao.search(hql);
		hql = "from DataDictionary where key='company' and description='extra'";
		List ddList = dao.search(hql);
		List data = new ArrayList();
		for(int i=0;i<d.size();i++){
			SysDepts sd = (SysDepts)d.get(i);
			DataDictionary dd = new DataDictionary();
			dd.setId(sd.getId());
			dd.setText(sd.getDeptCname());
			dd.setValue(sd.getId()+"");
			data.add(dd);
		}
		data.addAll(ddList);
		return data;
	}
}
